package com.hmall.api.client.item;

import com.hmall.api.dto.ItemDTO;
import com.hmall.api.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

@Slf4j
@Component
public class ItemClientFallbackFactory implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {

            /**
             * 根据ids批量查询商品
             * @param ids
             * @return
             */
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.error("远程调用ItemClient.queryItemByIds方法异常，参数：{}", ids, cause);
                return List.of();
            }


            @Override
            public void deductStock(List<OrderDetailDTO> dtos) {
                log.error("远程调用ItemClient.deductStock方法异常，参数：{}", dtos, cause);
            }

            /**
             * 将购买失败的商品  根据id+num 恢复
             * @param items
             */
            @Override
            public void SaveIdStack(List<OrderDetailDTO> items) {
                log.error("远程调用方法saveidstack 异常 参数：{}",items,cause);
            }

        };
    }
}
